/*
 *  ETInit.cpp
 *  EidoTron
 *
 *  Created by Luca Di Franco on 07/03/11.
 *  Copyright 2011 Luca Di Franco. All rights reserved.
 *
 */

#include "EidoTronApp.h"

bool EidoTronApp::setupWindow()
{
	if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
		return false;
	Uint32 flags = SDL_HWSURFACE | SDL_OPENGL /*| SDL_FULLSCREEN*/;
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,		1);
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE,			8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,			8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,			8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,			8);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,			16);
	SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE,			32);
	SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,		8);
	SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE,    8);
	SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,		8);
	SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE,    8);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,  1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,  4);
	displaySurface = SDL_SetVideoMode(800, 600, 32, flags); // width = 0 && height = 0 -> current screen resolution
	if (displaySurface == NULL) 
		return false;
	SDL_WM_SetCaption("EidoTron", "EidoTron");
	
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glViewport(0, 0, displaySurface->w, displaySurface->h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0, (double)displaySurface->w / (double)displaySurface->h, 0.1, 100.0);
	glEnable(GL_TEXTURE_2D);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	return true;
}